﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace store.Areas.Home.Controllers
{
    public class ProductController : Controller
    {
        private readonly storeEntities db = new storeEntities();
        //
        // GET: /Home/Product/


        [ChildActionOnly]
        public ActionResult SalesProduct()
        {
            return PartialView("_PartialSalesProduct", db.Products.Where(x => x.Sales > 0).ToList());
        }

        [ChildActionOnly]
        public ActionResult SidebarRandomProduct()
        {
            Random rd = new Random();
            return PartialView("_PartialSideBar", db.Products.ToList().GetRange(rd.Next(0, db.Products.Count() - 1), 2));
        }

        public ActionResult Detail(int id = 0)
        {
            Product product = db.Products.Find(id);
            if (product == null)
            {
                return HttpNotFound();
            }
            return View(product);
        }

    }
}
